//
//  ContentView.swift
//  swiftUIdemo
//
//  Created by Z.cy on 2025/1/8.
//

import SwiftUI
struct ContentView: View {
    @StateObject var appTabBarState = AppTabBarState()
    var body: some View {
        VStack {
            switch appTabBarState.selectedTab {
            case .home:
                HomeScreen()
                    .environmentObject(appTabBarState)
            case .live:
                LiveScreen()
//                    .environmentObject(appTabBarState)
            case .message:
                MessageListScreen()
                    .environmentObject(appTabBarState)
            case .profile:
                ProfileScreen()
            }
            if !appTabBarState.isTabBarHidden {
                Spacer()
                HStack {
                    createTabItem(tab: .home, title: "Home")
                    createTabItem(tab: .live, title: "Live")
                    createTabItem(tab: .message, title: "Message")
                    createTabItem(tab: .profile, title: "Profile")
                }
            }
        }
        .padding()
    }
    
    
    func createTabItem(tab: TabItem, title: String) -> some View {
        Button {
            appTabBarState.selectedTab = tab
        }
        label: {
            VStack {
                Image(systemName: tab.rawValue)
                    .font(.system(size: 24, weight: .bold))
                    .foregroundColor(appTabBarState.selectedTab == tab ? .accentColor : .gray.opacity(0.5))
                    .frame(maxWidth: .infinity)
                Text(title)
                    .font(.system(size: 10))
                    .foregroundColor(appTabBarState.selectedTab == tab ? .accentColor : .gray.opacity(0.5))
            }
        }
    }
}

#Preview {
    ContentView()
}
